﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Pahan.McuFusion.Common;
using Pahan.McuFusion.UI.Interfaces.NewWorkspaceWizardPages;

namespace Pahan.McuFusion.UI.Views.NewWorkspaceWizardPages
{
    public partial class HardwareAdapterPage : UserControl, IHardwareAdapterPage
    {
        public HardwareAdapterPage()
        {
            InitializeComponent();
        }

        #region Implementation of IWizardPage

        /// <summary>
        /// Gets the title of the page.
        /// </summary>
        public string Title
        {
            get
            {
                return "Hardware Protocol Adapter";
            }
        }

        #endregion

        #region Implementation of IHardwareAdapterPage

        /// <summary>
        /// Shows the list of the available adapters.
        /// </summary>
        public void ShowAdapters(IList<HardwareAdapterInfo> adapters)
        {
            lstHardwareAdapters.DataSource = adapters;
            if (adapters.Count > 0)
            {
                lstHardwareAdapters.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// Gets the selected adapter.
        /// </summary>
        public HardwareAdapterInfo SelectedAdapter
        {
            get
            {
                return lstHardwareAdapters.SelectedItem as HardwareAdapterInfo;
            }
        }

        public event EventHandler SelectedAdapterChanged;

        #endregion

        private void lstHardwareAdapter_SelectedIndexChanged(object sender, EventArgs e)
        {
            var handler = SelectedAdapterChanged;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}
